clear;
%% input: 
%  1. subject num
%  2. evaluation: pre / post       
%  3. task: fr / lr 
%  5. load data folder & save kinematics.mat folder.

num_choose = {'05', '06', '07_1', '08', '09', '10', '11', '14', '16','17','18','19','20','22','23','25','26'};
num_choose = {'05'};
eva_choose = {'pre','post'};
task_choose = {'LR','FR'};

% fixed parameter
fs=1000;
mid=400;

% choose data path & save path
[subject_folder,data_roi_save,sep_typle] = file_path();

for si = 1:1:length(num_choose)
    subject_num = num_choose(si);
    
    for eva_i = 1:1:length(eva_choose)
        eva = eva_choose(eva_i);
        
       % creat new folder for new subject
       new_folder_path_1 = strcat(data_roi_save,'s',subject_num,'_',eva);
       mkdir(new_folder_path_1{1,1})
        for task_i = 1:1:length(task_choose)
            task = task_choose(task_i);
             new_folder_path_2 = strcat(new_folder_path_1{1,1},sep_typle,task);
             mkdir(new_folder_path_2{1,1})
            % subject data path:
            subject_data = strcat(subject_folder,'s',subject_num,'_',eva,sep_typle,task,sep_typle);
       
            Files = dir(subject_data{1,1});
            LengthFiles = length(Files);
            
            % preprocess kinematics
            for j = 3:LengthFiles
                % load raw data
               [raw_data] = load_raw_data(subject_data,Files,j);
                % calculate onset & offset
               [movement] = calculate_onset_offset( raw_data,fs,mid );
               [EMG_Motion_roi] = calculate_kinematics_data(raw_data,fs,mid,movement); % Kinematics
               % save .csv file
               save_csv(EMG_Motion_roi,new_folder_path_2,subject_num,Files,j)
            end
           
             clear EMG_Motion_roi
             
        end
    end
end



